﻿using System;
using System.Globalization;
using System.IO;

using Abstract2ion.Properties;

namespace Abstract2ion
{
    public class FileSystemWrapper : IFileSystemWrapper
    {
        public IDirectoryItem CurrentDirectory
        {
            get { return new DirectoryItem(Environment.CurrentDirectory); }
        }

        public IDirectoryItem FindDirectory(string path)
        {
            var directoryInfo = new DirectoryInfo(path);

            if (!directoryInfo.Exists)
            {
                throw new DirectoryNotFoundException(string.Format(CultureInfo.CurrentCulture, Resources.DirectoryNotFoundErrorFormat, path));
            }

            return new DirectoryItem(directoryInfo);
        }

        public IFileItem FindFile(string path)
        {
            var fileInfo = new FileInfo(path);

            if (!fileInfo.Exists)
            {
                throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Resources.FileNotFoundErrorFormat, path));
            }

            return new FileItem(fileInfo);
        }
    }
}